package com.qf.boot.service.consumer;

import com.qf.boot.service.api.SiteService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;

@EnableAutoConfiguration
public class MockDubboConsumer {

    /**
     * 服务的降级，就是消费者自己降配置mock
     * 当配置fail时会请求生产者
     * 当配置force时不会请求生产者
     *
     * failover 容错默认方式是重试2次，解决方法生产者幂等性（写操作）
     * 1》业务主键ID 组成联合主键，确保业务主键唯一
     * 2》分布式锁
     *
     *
     *
     */
    //fail:return backtime
    @Reference(version = "timeout",timeout = 2000,mock = "force:return hello self")
    private SiteService siteService;

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(MockDubboConsumer.class);
        SiteService ss = (SiteService) context.getBean(SiteService.class);
        String name  = ss.getName("q-kafka");
        System.out.println(name);
    }
}
